#include "utility.h"

Utility::Utility()
{

}


/**
    Positional Strategy for Reversi
    http://samsoft.org.uk/reversi/strategy.htm
*/
int Utility::evaluate(Node *node){
    //return node->get_board()->get_score();
    int value = 0;
    for ( int col = 0; col < 7; col++){
        for (int row = 0; row < 7; row++){
            /* Corners */
            if ((col == 0 && row == 0) ||
                (col == 0 && row == 7) ||
                (col == 7 && row == 0) ||
                (col == 7 && row == 7) ){
                if ( node->get_board()->get_piece(col, row) == 1){
                    value += 99;
                }

            }

            /* C Squares */
            if ((col == 0 && row == 1) ||
                (col == 0 && row == 6) ||
                (col == 1 && row == 0) ||
                (col == 1 && row == 7) ||
                (col == 6 && row == 0) ||
                (col == 6 && row == 7) ||
                (col == 7 && row == 0) ||
                (col == 7 && row == 6)){

                if ( node->get_board()->get_piece(col, row) == 1){
                    value -= 8;
                }
            }
            /* A Squares */
            if ((col == 0 && row == 2) ||
                (col == 0 && row == 5) ||
                (col == 2 && row == 0) ||
                (col == 2 && row == 7) ||
                (col == 5 && row == 0) ||
                (col == 5 && row == 7) ||
                (col == 7 && row == 2) ||
                (col == 7 && row == 5) ){
                if ( node->get_board()->get_piece(col, row) == 1){
                    value += 8;
                }
            }

            /* B Squares */
            if ((col == 0 && row == 3) ||
                (col == 0 && row == 4) ||
                (col == 3 && row == 0) ||
                (col == 3 && row == 7) ||
                (col == 4 && row == 0) ||
                (col == 4 && row == 7) ||
                (col == 7 && row == 3) ||
                (col == 7 && row == 4) ){
                if ( node->get_board()->get_piece(col, row) == 1){
                    value += 6;
                }
            }

            /* X Squares */
            if ((col == 1 && row == 1) ||
                (col == 1 && row == 6) ||
                (col == 6 && row == 1) ||
                (col == 6 && row == 6)){
                if ( node->get_board()->get_piece(col, row) == 1){
                    value -= 24;
                }
            }


            if ((col == 1 && row == 2) ||
                (col == 1 && row == 5) ||
                (col == 2 && row == 1) ||
                (col == 2 && row == 6) ||
                (col == 5 && row == 1) ||
                (col == 5 && row == 6) ||
                (col == 6 && row == 2) ||
                (col == 6 && row == 5)){
               if ( node->get_board()->get_piece(col, row) == 1){
                    value -= -4;
                }
            }

            if ((col == 1 && row == 3) ||
                (col == 1 && row == 4) ||
                (col == 3 && row == 1) ||
                (col == 3 && row == 6) ||
                (col == 4 && row == 1) ||
                (col == 4 && row == 6) ||
                (col == 6 && row == 3) ||
                (col == 6 && row == 4)){
               if ( node->get_board()->get_piece(col, row) == 1){
                    value -= 3;
                }
            }

            if ((col == 2 && row == 2) ||
                (col == 2 && row == 5) ||
                (col == 5 && row == 2) ||
                (col == 5 && row == 5)){
                if ( node->get_board()->get_piece(col, row) == 1){
                    value += 7;
                }
            }

            if ((col == 2 && row == 3) ||
                (col == 2 && row == 4) ||

                (col == 3 && row == 2) ||
                (col == 3 && row == 5) ||

                (col == 4 && row == 2) ||
                (col == 4 && row == 5) ||

                (col == 5 && row == 3) ||
                (col == 5 && row == 4) ){
                if ( node->get_board()->get_piece(col, row) == 1){
                   value += 4;
                }
            }
        }

    }
    return value;
}

